﻿using System.Collections.Generic;
using System.Diagnostics;

namespace Runtime.Services.Battle.Entity {

    /// <summary>
    /// 实体类型
    /// </summary>
    [DebuggerStepThrough]
    [DebuggerNonUserCode]
    public readonly struct DFR_BattleEntityType {

        public static readonly DFR_BattleEntityType Unknown = new() { Value = 0 };
        public static readonly DFR_BattleEntityType AttackSource = new() { Value = 1 << 0 };
        public static readonly DFR_BattleEntityType AttackTarget = new() { Value = 1 << 1 };
        public static readonly DFR_BattleEntityType Bullet = new() { Value = 1 << 2 };
        public static readonly DFR_BattleEntityType Effect = new() { Value = 1 << 3 };
        public static readonly DFR_BattleEntityType Skill = new() { Value = 1 << 4 };
        public static readonly DFR_BattleEntityType Cell = new() { Value = 1 << 5 };
        public static readonly DFR_BattleEntityType Holder = new() { Value = 1 << 6 };
        public static readonly DFR_BattleEntityType Player = new() { Value = 1 << 7 };
        public static readonly DFR_BattleEntityType Talent = new() { Value = 1 << 8 };
        public static readonly DFR_BattleEntityType Object = new() { Value = 1 << 9 };
        public static readonly DFR_BattleEntityType Roguelike = new() { Value = 1 << 10 };

        private static readonly IReadOnlyDictionary<DFR_BattleEntityType, string> NAME_DICTIONARY = new Dictionary<DFR_BattleEntityType, string> {
            { Unknown, nameof(Unknown) },
            { AttackSource, nameof(AttackSource) },
            { AttackTarget, nameof(AttackTarget) },
            { Bullet, nameof(Bullet) },
            { Effect, nameof(Effect) },
            { Skill, nameof(Skill) },
            { Cell, nameof(Cell) },
            { Holder, nameof(Holder) },
            { Player, nameof(Player) },
            { Talent, nameof(Talent) },
            { Object, nameof(Object) },
            { Roguelike, nameof(Roguelike) },
        };

        /// <summary>
        /// 值
        /// </summary>
        public int Value { get; init; }

        public override bool Equals(object obj) {
            if (obj is DFR_BattleEntityType other) {
                return other.Value == Value;
            }
            return false;
        }

        public override int GetHashCode() => Value.GetHashCode();

        public static bool operator ==(DFR_BattleEntityType left, DFR_BattleEntityType right) => left.Equals(right);

        public static bool operator !=(DFR_BattleEntityType left, DFR_BattleEntityType right) => !left.Equals(right);

        public override string ToString() {
            if (NAME_DICTIONARY.TryGetValue(this, out var name)) {
                return name;
            } else {
                return $"{nameof(DFR_BattleEntityType)}({Value})";
            }
        }
    }
}
